package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.account.CheckingAccount;
import com.acme.bankapp.domain.account.SavingsAccount;
import com.acme.bankapp.domain.bank.*;
import com.acme.bankapp.domain.client.Client;
import com.acme.bankapp.domain.client.Gender;
import com.acme.bankapp.domain.exception.ClientExistsException;
import com.acme.bankapp.domain.exception.NotEnoughFundsException;


public class BankApplication {
	
	public static void addClient(Bank bank, Client client){
		
		try {
			BankService.addClient(bank, client);
		} catch (ClientExistsException e) {
			System.out.println(e.getMessage());
		}
		
	}
	
	public static void  withdraw(Client client, double sum){
		try {
			client.getAccount().withdraw(sum);
		} catch (NotEnoughFundsException e) {
			System.out.println(e.getMessage());
		}
		
	}

	public static void modifyBank(){
		
		BankService bankService = new BankService();
		Bank bank = BankService.createNewBank();
		
		Client client1 = new Client("Ivanov", Gender.MALE, (new CheckingAccount(50, 100)));
		Client client2 = new Client("Petrova", Gender.FEMALE, (new CheckingAccount(30)));
		Client client3 = new Client("Ivanov", Gender.MALE, (new CheckingAccount(50, 100)));
		Client client4 =  new Client("Sidorov", Gender.MALE, (new SavingsAccount(100)));
		
		addClient(bank, client1);
		addClient(bank, client2);
		addClient(bank, client3);
		addClient(bank, client4);
			
		BankService.printBalance(bank);
		
		System.out.println("------");
		
		withdraw(client1, 200);
		withdraw(client4, 150);
		
		assert((client1.getAccount()).isValidBalance());
		client2.getAccount().deposit(30);
		
		BankService.printBalance(bank);
		
		
	}
	
	public static void main(String[] args) {

		modifyBank();

	}

}
